// 规则列表
export function ruleColumns() {
  const COLUMN_WIDTH = window.RPConfig.COLUMN_WIDTH
  return [
    {
      type: "selection",
      width: 50,
      align: "center"
    },
    {
      title: this.$t("module.dataPermission.ruleCode"),
      key: "code",
      minWidth: 160,
      sortable: "custom",
      render: (h, params) => {
        return h(
          "div",
          {
            attrs: {
              class: "ivu-table-cell ivu-table-cell-ellipsis",
              title: params.row.code
            }
          },
          params.row.code
        );
      }
    },
    {
      title: this.$t("module.dataPermission.ruleName"),
      key: "name",
      minWidth: 160,
      sortable: "custom",
      render: (h, params) => {
        return h(
          "div",
          {
            attrs: {
              class: "ivu-table-cell ivu-table-cell-ellipsis",
              title: params.row.name
            }
          },
          params.row.name
        );
      }
    },
    {
      title: this.$t("module.dataPermission.shieldingObject"),
      key: "target",
      align: "center",
      minWidth: COLUMN_WIDTH.COLUMN_WIDTH_4_WORDS,
      maxWidth: COLUMN_WIDTH.COLUMN_WIDTH_4_WORDS + COLUMN_WIDTH.MAX_WIDTH_MORE,
      render: (h, params) => {
        return h(
          "div",
          {
            attrs: {
              class: "ivu-table-cell ivu-table-cell-ellipsis",
              title: this.objectList[params.row.target]
            }
          },
          this.objectList[params.row.target]
        );
      }
    },
    {
      title: this.$t("module.dataPermission.controlLevel"),
      key: "level",
      align: "center",
      minWidth: COLUMN_WIDTH.COLUMN_WIDTH_4_WORDS,
      maxWidth: COLUMN_WIDTH.COLUMN_WIDTH_4_WORDS + COLUMN_WIDTH.MAX_WIDTH_MORE,
      render: (h, params) => {
        return h(
          "div",
          {
            attrs: {
              class: "ivu-table-cell ivu-table-cell-ellipsis",
              title: this.controlLevelList[params.row.level]
            }
          },
          this.controlLevelList[params.row.level]
        );
      }
    },
    {
      title: this.$t("common.status"),
      key: "enabled",
      align: "center",
      minWidth: 80,
      maxWidth: 80 + COLUMN_WIDTH.MAX_WIDTH_MORE,
      render: (h, params) => {
        return h(
          "StatusButton",
          {
            // 修改StatusButton内容居中
            style: {
              "justify-content": "center"
            },

            props: {
              status: params.row.enabled == 1 ? "0" : "1"
            }
          },
          params.row.enabled ? this.$t("common.enable") : this.$t("common.disable")
        );
      }
    },
    {
      title: this.$t("common.operating"),
      align: "left",
      fixed: "right",
      width: 90,
      render: (h, params) => {
        return h("RowTools", {
          props: {
            data: this.getOperations(params.row)
          }
        });
      }
    }
  ];
}

// 分配维度列表
export function dimensionColumns() {
  return [
    {
      type: "selection",
      width: 55,
      align: "center"
    },
    {
      title: this.$t("module.dimension.dimensionCode"),
      key: "dimensionCode",
      render: (h, params) => {
        return h(
          "span",
          {
            attrs: {
              title: params.row.dimensionCode
            }
          },
          params.row.dimensionCode
        );
      }
    },
    {
      title: this.$t("module.dimension.dimensionName"),
      key: "dimensionName",
      render: (h, params) => {
        return h(
          "span",
          {
            attrs: {
              title: params.row.dimensionName
            }
          },
          params.row.dimensionName
        );
      }
    }
  ];
}

// 分配角色
export function assignRoleColumns() {
  return [
    {
      type: "selection",
      width: 45,
      align: "center"
    },
    {
      title: this.$t("module.role.roleName"),
      key: "roleName",
      render: (h, params) => {
        return h(
          "div",
          {
            attrs: {
              class: "ivu-table-cell ivu-table-cell-ellipsis",
              title: params.row.roleName
            }
          },
          params.row.roleName
        );
      }
    },
    {
      title: this.$t("module.role.roleCode"),
      key: "roleCode",
      render: (h, params) => {
        return h(
          "div",
          {
            attrs: {
              class: "ivu-table-cell ivu-table-cell-ellipsis",
              title: params.row.roleCode
            }
          },
          params.row.roleCode
        );
      }
    },
    {
      title: this.$t("common.operating"),
      align: "center",
      fixed: "right",
      width: 55,
      render: (h, params) => {
        return h("RowTools", {
          props: {
            data: [
              {
                type: "icon",
                icon: "ios-trash",
                text: this.$t("common.delete"),
                handle: () => {
                  this.deleted(params.row.id);
                }
              }
            ]
          }
        });
      }
    }
  ];
}

// 选择角色
export function selectRoleColumns() {
  return [
    {
      type: "selection",
      width: 45,
      align: "center"
    },
    {
      title: this.$t("module.role.roleCode"),
      key: "roleCode",
      render: (h, params) => {
        return h(
          "div",
          {
            attrs: {
              class: "ivu-table-cell ivu-table-cell-ellipsis",
              title: params.row.roleCode
            }
          },
          params.row.roleCode
        );
      }
    },
    {
      title: this.$t("module.role.roleName"),
      key: "roleName",
      render: (h, params) => {
        return h(
          "div",
          {
            attrs: {
              class: "ivu-table-cell ivu-table-cell-ellipsis",
              title: params.row.roleName
            }
          },
          params.row.roleName
        );
      }
    }
  ];
}

// 分配用户
export function assignUserColumns() {
  return [
    {
      type: "selection",
      width: 45,
      align: "center"
    },
    {
      title: this.$t("module.userManage.name"),
      key: "userName",
      minWidth: 100,
      render: (h, params) => {
        return h(
          "div",
          {
            attrs: {
              class: "ivu-table-cell ivu-table-cell-ellipsis",
              title: params.row.userName
            }
          },
          params.row.userName
        );
      }
    },
    {
      title: this.$t("module.userManage.account"),
      key: "userId",
      minWidth: 100,
      render: (h, params) => {
        return h(
          "div",
          {
            attrs: {
              class: "ivu-table-cell ivu-table-cell-ellipsis",
              title: params.row.userId
            }
          },
          params.row.userId
        );
      }
    },
    {
      title: this.$t("module.userManage.org"),
      key: "orgPath",
      minWidth: 100,
      render: (h, params) => {
        if (params.row._hasOrgInfo) {
          return h(
            "div",
            {
              attrs: {
                class: "ivu-table-cell ivu-table-cell-ellipsis",
                title: params.row.orgNameFullPath
              }
            },
            params.row.orgName
          );
        } else {
          return h("Spin", [
            h("Icon", {
              props: {
                type: "ios-loading",
                size: 18
              },
              class: "spin-icon-load"
            })
          ]);
        }
      }
    },
    {
      title: this.$t("common.operating"),
      // align: "center",
      fixed: "right",
      width: 55,
      render: (h, params) => {
        return h("RowTools", {
          props: {
            data: [
              {
                type: "icon",
                icon: "ios-trash",
                text: this.$t("common.delete"),
                handle: () => {
                  this.deleted(params.row.id);
                }
              }
            ]
          }
        });
      }
    }
  ];
}

// 选择用户
export function selectUserColumns() {
  return [
    {
      type: "selection",
      width: 45,
      align: "center"
    },
    {
      title: this.$t("module.userManage.account"),
      key: "userId",
      width: 160,
      render: (h, params) => {
        return h(
          "div",
          {
            attrs: {
              class: "ivu-table-cell ivu-table-cell-ellipsis",
              title: params.row.userId
            }
          },
          params.row.userId
        );
      }
    },
    {
      title: this.$t("module.userManage.name"),
      key: "userName",
      width: 160,
      render: (h, params) => {
        return h(
          "div",
          {
            attrs: {
              class: "ivu-table-cell ivu-table-cell-ellipsis",
              title: params.row.userName
            }
          },
          params.row.userName
        );
      }
    },
    {
      title: this.$t("module.userManage.org"),
      key: "orgPath",
      width: 130,
      render: (h, params) => {
        if (params.row._hasOrgInfo) {
          return h(
            "div",
            {
              attrs: {
                class: "ivu-table-cell ivu-table-cell-ellipsis",
                title: params.row.orgNameFullPath
              }
            },
            params.row.orgName
          );
        } else {
          return h("Spin", [
            h("Icon", {
              props: {
                type: "ios-loading",
                size: 18
              },
              class: "spin-icon-load"
            })
          ]);
        }
      }
    },
    {
      title: this.$t("module.userManage.cellPhoneNumber"),
      key: "mobile",
      width: 120
    },
    {
      title: this.$t("module.userManage.email"),
      key: "email"
    }
  ];
}

// 分配维度数据
export function dimensionDataColumns() {
  return [
    {
      type: "selection",
      width: 55,
      align: "center"
    },
    {
      title: this.$t("module.dimension.code"),
      key: "dimensionDataCode",
      render: (h, params) => {
        return h(
          "div",
          {
            attrs: {
              class: "ivu-table-cell ivu-table-cell-ellipsis",
              title: params.row.dimensionDataCode
            }
          },
          params.row.dimensionDataCode
        );
      }
    },
    {
      title: this.$t("module.dimension.name"),
      key: "dimensionDataName",
      render: (h, params) => {
        return h(
          "div",
          {
            attrs: {
              class: "ivu-table-cell ivu-table-cell-ellipsis",
              title: params.row.dimensionDataName
            }
          },
          params.row.dimensionDataName
        );
      }
    },
    {
      title: this.$t("common.operating"),
      align: "center",
      fixed: "right",
      width: 55,
      render: (h, params) => {
        return h("RowTools", {
          props: {
            data: [
              {
                type: "icon",
                icon: "ios-trash",
                text: this.$t("common.delete"),
                handle: () => {
                  this.deleted(params.row.id);
                }
              }
            ]
          }
        });
      }
    }
  ];
}

export function selectDimensionDataColumns() {
  return [
    {
      type: "selection",
      width: 45,
      align: "center"
    },
    {
      title: this.$t("module.dimension.code"),
      key: "dimensionDataCode",
      render: (h, params) => {
        return h(
          "div",
          {
            attrs: {
              class: "ivu-table-cell ivu-table-cell-ellipsis",
              title: params.row.dimensionDataCode
            }
          },
          params.row.dimensionDataCode
        );
      }
    },
    {
      title: this.$t("module.dimension.name"),
      key: "dimensionDataName",
      render: (h, params) => {
        return h(
          "div",
          {
            attrs: {
              class: "ivu-table-cell ivu-table-cell-ellipsis",
              title: params.row.dimensionDataName
            }
          },
          params.row.dimensionDataName
        );
      }
    }
  ];
}
